package cn.matezk.cloud.model;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.util.ObjectUtil;
import cn.matezk.cloud.beans.NotifyConfig;
import cn.matezk.cloud.utils.StringUtils;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;

import java.math.BigDecimal;
import java.util.Date;

@Data
public class Device {
    private String deviceId;
    private String appId;
    private String productId;
    private String deviceName;
    private String iccid;
    private BigDecimal longitude;
    private BigDecimal latitude;
    private String familyId;
    private String roomId;
    private String aliasName;
    private NotifyConfig notifyConfig;
    @JsonFormat(pattern = DatePattern.NORM_DATE_PATTERN, timezone="GMT+8")
    private Date exFactoryTime;
    @JsonFormat(pattern = DatePattern.NORM_DATE_PATTERN, timezone="GMT+8")
    private Date expireDate;
    private Integer amount;
    private Long deptId;

    public String getAmountText() {
        return StringUtils.amount(amount);
    }

    public String getDeviceId() {
        return ObjectUtil.isEmpty(deviceId) ? productId.concat("/").concat(deviceName) : deviceId;
    }

    public static String createLockKey(String deviceId) {
        return "lock.device.".concat(deviceId);
    }
}
